#ifndef CAN_H
#define CAN_H
#include "CAN_TO_USB.h"
#include <QList>
#include "cals.h"

class Can : public QObject
{
    Q_OBJECT
public:
    int id_equipment;
    int id_device;
    VCI_INIT_CONFIG init_config;//initial config

    VCI_CAN_OBJ can_obj_send;//send data obj
    QList<VCI_CAN_OBJ> can_obj_recieve_list;//recieve data obj list

    //send data obj properities
    const UCHAR send_type = 0;
    const UCHAR remote_flag = 0;
    const UCHAR extern_flag = 0;
    const UCHAR data_len = 8;

public:
    explicit Can(int,int,QObject *parent = nullptr);
    explicit Can(QObject *parent = nullptr);

    bool connect() const;
    void set_ids(const int equipment, const int device);
    bool set_config(const QString& acc_code,const QString& acc_mask,const QString& filter,const QString& timing0,const QString& timing1,const QString& mode);
    bool send_data(const QString& id_lower_computer,const QString& data0,const QString& data1,const QString& data2,const QString& data3);
    bool send_data(const QString& id_lower_computer,const QStringList& datas);
    LONGLONG recieve_data(const QString& len,const QString& wait_time, QList<VCI_CAN_OBJ>& outputs) const;
    QList<VCI_CAN_OBJ> recieve_data(const QString& len,const QString& wait_time) const;
    bool close();
    DWORD get_residue_cnts();
    bool clear_buffer();

    void set_send_obj(const UCHAR, const UCHAR, const UCHAR, const UCHAR);

private:
    DWORD qstr2dword_hex(const QString&)const;
    UCHAR qstr2uchar_hex(const QString&)const;
    void set_default_can_obj();
};

#endif // CAN_H
